package com.mju.byc.controllers;

import com.mju.byc.Repository.BookRepository;
import com.mju.byc.pojo.Author;
import com.mju.byc.pojo.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class MainController {
    @Autowired
    private BookRepository bookRepository;
    @RequestMapping("/initData")
    @ResponseBody
    public Iterable<Book> index(){

        Book book1 = new Book();
        Book book2 = new Book();
        Author author1 = new Author();
        Author author2 = new Author();
        author1.setAge(19);
        author2.setAge(20);
        author1.setName("byc");
        author2.setName("yty");
        book1.setName("母猪的产后护理");
        book1.setPrice(66);
        book1.setAuthor(author1);
        book2.setName("演员的自我修养");
        book2.setPrice(77);
        book2.setAuthor(author2);
        bookRepository.save(book1);
        bookRepository.save(book2);

        return bookRepository.findAll();
    }

}
